package com.dsteiner.widgets.client.rpc;

import com.dsteiner.widgets.client.domain.BaseObject;
import com.dsteiner.widgets.client.domain.SearchableProperty;
import com.dsteiner.widgets.client.domain.Sort;

public interface SearchRequest{

	public static int TYPE_ALL = 2;
	public static int TYPE_BETWEEN = 3;
	public static int TYPE_EQUALS = 0;
	public static int TYPE_PREFIX = 1;
	
	public static class SearchRequestImpl extends BaseObject implements SearchRequest{
		
		private String text;
		private String className;
		private Sort sort;
		private int offset;
		private int limit = 10;
		private String annotationClassName = SearchableProperty.class.getName();
		private int type = TYPE_EQUALS;
		private String toFieldName;
		private String fromFieldName;
		
		public SearchRequestImpl() {
		}
		
		public SearchRequestImpl(String text, String className, Sort sort, int offset, int limit) {
			this.text = text;
			this.className = className;
			this.sort = sort;
			this.offset = offset;
			this.limit = limit;
		}
		
		public void setType(int type) {
			this.type = type;
		}
		public int getType() {
			return type;
		}
		public String getAnnotationClassName() {
			return annotationClassName;
		}
		public void setAnnotationClassName(String annotationClassName) {
			this.annotationClassName = annotationClassName;
		}
		public void setOffset(int offset) {
			this.offset = offset;
		}
		public int getOffset() {
			return offset;
		}
		public int getLimit() {
			return limit;
		}
		public void setLimit(int limit) {
			this.limit = limit;
		}
		public void setText(String text) {
			this.text = text;
		}
		public String getText() {
			return text;
		}
		public String getClassName() {
			return className;
		}
		public void setClassName(String className) {
			this.className = className;
		}
		public void setSort(Sort sort) {
			this.sort = sort;
		}
		public Sort getSort() {
			return sort;
		}
	
		public void setFromFieldName(String fromFieldName) {
			this.fromFieldName = fromFieldName;
		}
		public void setToFieldName(String toFieldName) {
			this.toFieldName = toFieldName;
		}
		@Override
		public String toString() {
			return text+"|"+className+"|"+sort+"|"+offset+"|"+limit+"|"+annotationClassName+"|"+type;
		}
	
		public boolean isEquals() {
			return type == TYPE_EQUALS;
		}
		public boolean isAll() {
			return type == TYPE_ALL;
		}
		public boolean isBetween() {
			return type == TYPE_BETWEEN;
		}
		public boolean isPrefix() {
			return type == TYPE_PREFIX;
		}

		public String getFromFieldName() {
			return fromFieldName;
		}

		public String getToFieldName() {
			return toFieldName;
		}
	}

	String getText();

	boolean isAll();
	
	boolean isBetween();

	boolean isPrefix();

	boolean isEquals();

	int getType();

	String getAnnotationClassName();

	int getOffset();

	int getLimit();

	Sort getSort();

	String getClassName();
	
	void setClassName(String className);
	
	void setText(String text);
	
	void setOffset(int offset);
	
	void setLimit(int limit);

	void setSort(Sort sort);

	String getFromFieldName();

	String getToFieldName();
}

